﻿using System;
using System.Windows.Forms;

namespace Kay.Client.Demo
{
    public partial class Broadcast : Form
    {
        private TcpInterNetworkStreamClient _client;

        public Broadcast(TcpInterNetworkStreamClient client)
        {
            InitializeComponent();

            _client = client;
        }

        public void ReceivedText(string name, string msg)
        {
            if (textBox_Message.InvokeRequired)
            {
                textBox_Message.Invoke(new Action<string,string>(ReceivedText),name, msg);
                return;
            }
            if (textBox_Message.Lines.Length > 0)
            {
                textBox_Message.AppendText(Environment.NewLine);
                textBox_Message.AppendText(Environment.NewLine);
            }
            textBox_Message.AppendText(name + " 说：");
            textBox_Message.AppendText(Environment.NewLine);
            textBox_Message.AppendText(msg);
        }

        private void button_Send_Click(object sender, EventArgs e)
        {
            if (textBox_Send.Text == string.Empty) return;
            _client.SendTextBroadcast(textBox_Send.Text);
            if (textBox_Message.Lines.Length > 0)
            {
                textBox_Message.AppendText(Environment.NewLine);
                textBox_Message.AppendText(Environment.NewLine);
            }
            textBox_Message.AppendText("我 说" + "：");
            textBox_Message.AppendText(Environment.NewLine);
            textBox_Message.AppendText(textBox_Send.Text);
            textBox_Send.Clear();
        }
    }
}
